package cn.geminis.warehouse.service.basic.entity;

import cn.geminis.lowcode.annotation.*;
import com.alibaba.excel.annotation.ExcelProperty;
import jakarta.persistence.Column;
import jakarta.persistence.ManyToOne;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * 商品批次
 */
@Getter
@Setter
@UuidEntity(idFieldAnnotations = {"com.alibaba.excel.annotation.ExcelIgnore"})
@SoftDeleteEntity(deleteFieldAnnotations = {"com.alibaba.excel.annotation.ExcelIgnore"})
@QueryFilter
@CrudRepository
@CrudController
@ExcelController
public class ProductBatch {

    /**
     * 商品
     */
    @ManyToOne(optional = false)
    @QueryFilterProperty(fieldName = "product.id", propertyName = "productId", propertyType = "String")
    @QueryFilterProperty(fieldName = "product.name", propertyName = "productNameLike", propertyType = "String", filterType = QueryFilterProperty.FilterType.Like, valueFormat = "%%%s%%")
    @QueryFilterProperty(fieldName = "product.no", propertyName = "productNoLike", propertyType = "String", filterType = QueryFilterProperty.FilterType.Like, valueFormat = "%%%s%%")
    @ExcelProperty(value = "物品", converter = Product.ProductConverter.class)
    private Product product;

    /**
     * 供应商
     */
    @ManyToOne(optional = false)
    @QueryFilterProperty(fieldName = "vendor.id", propertyName = "vendorId", propertyType = "String")
    @QueryFilterProperty(fieldName = "vendor.name", propertyName = "vendorNameLike", propertyType = "String", filterType = QueryFilterProperty.FilterType.Like, valueFormat = "%%%s%%")
    @ExcelProperty(value = "供应商", converter = Vendor.VendorConverter.class)
    private Vendor vendor;

    /**
     * 批次号
     */
    @Column(nullable = false)
    @ExcelProperty("批次号")
    @QueryFilterProperty(filterType = QueryFilterProperty.FilterType.Like, valueFormat = "%%%s%%")
    private String no;

    /**
     * 有效期
     */
    @Column(nullable = false)
    @ExcelProperty("有效期")
    private LocalDate validTo;

    /**
     * 单价
     */
    @Column(nullable = false)
    @ExcelProperty("单价")
    private BigDecimal price;

//    /**
//     * 可用数量
//     */
//    @Column(nullable = false)
//    private int amount;

//    /**
//     * 批次属性
//     */
//    @Type(type = "json")
//    @Column(columnDefinition = "json")
//    private Object properties;

}
